package com.xiaomei.manager.web.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.xiaomei.manager.model.SysResource;
import com.xiaomei.manager.model.SysUser;
import com.xiaomei.manager.service.IResourceService;
import com.xiaomei.manager.service.ISysUserService;
import com.xiaomei.manager.shiro.web.bind.annotation.CurrentUser;

import java.util.List;
import java.util.Set;

/**
 * <p>User: Zhang Kaitao
 * <p>Date: 14-2-14
 * <p>Version: 1.0
 */
@Controller
public class IndexController {

    @Autowired
    private IResourceService resourceService;
    @Autowired
    private ISysUserService userService;
    /**
     * 拦截器中拦截的登录用户对象
     * @param loginUser
     * @param model
     * @return
     */
    @RequestMapping("/")	
    public String index(@CurrentUser SysUser loginUser, Model model) {
        Set<String> permissions = userService.findPermissions(loginUser.getUsername());
        List<SysResource> menus = resourceService.findMenus(permissions);
        model.addAttribute("menus", menus);
        return "index";
    }

    @RequestMapping("/welcome")
    public String welcome() {
        return "welcome";
    }


}
